//                        date: [[20120731120157]]
//                        Author: Ahmed Fathi Hamouda Abd El Hafez
using System;
using System.ComponentModel;
using System.Reflection;
using System.Data;
using CustomersSuppliersDataLayer;
using System.Collections.Generic;


namespace CustomersSuppliersBusinessLayer
{

    /// <summary>
    ///  Business Object OF Table DealersClassifications
    /// </summary>

    public partial class BLDealersClassification : INotifyPropertyChanged
    {
        #region Fields
        private BLDealersClassification.BusinessRelatedObjects f_RelatedObjects = null;
        #endregion

        #region properties
        /// <summary>
        /// keys object of BLDealersClassification
        /// </summary>
        [Browsable(false)]
        public BLDealersClassification.BusinessRelatedObjects RelatedObjects
        {
            get
            {
                if (this.f_RelatedObjects == null)
                {
                    this.f_RelatedObjects = new BusinessRelatedObjects(this);
                }
                return f_RelatedObjects;
            }
            set
            {
                f_RelatedObjects = value;
            }
        }
        #endregion

        #region RelatedObjects
        /// <summary>
        /// contains properties of the Related Objects 
        /// </summary>
        [Serializable]
        public partial class BusinessRelatedObjects
        {
            private BLDealersClassification containerObject = null;
            private Dictionary<string, string> RelatedObjectsMappings = new Dictionary<string, string>();

            private BLDealersType f_ObjectOfDealerType_ID = null;

            /// <summary>
            /// returns the BLDealersType Object that Corresponds to DealerType_ID property
            /// </summary>
            public BLDealersType ObjectOfDealerType_ID
            {
                get
                {
                    if (this.f_ObjectOfDealerType_ID == null)
                    {
                        this.f_ObjectOfDealerType_ID = new BLDealersType();
                        if (containerObject.DealerType_ID != null)
                        {
                            this.f_ObjectOfDealerType_ID.DealerType_ID = containerObject.DealerType_ID;
                            this.f_ObjectOfDealerType_ID.LoadByProperties(new string[] { BLDealersClassification.PropertiesNames.DealerType_ID });
                        }
                    }
                    return this.f_ObjectOfDealerType_ID;
                }
            }

            public BusinessRelatedObjects(BLDealersClassification item)
            {
                this.containerObject = item;
                if (this.containerObject != null)
                {
                    this.containerObject.PropertyChanged += new PropertyChangedEventHandler(this.containerObject_PropertyChanged);
                    this.containerObject.AfterLoad += new EventHandler(this.containerObject_AfterLoad);
                }
                RelatedObjectsMappings.Add(BLDealersClassification.PropertiesNames.DealerType_ID, "f_ObjectOfDealerType_ID");
            }
            public void ResetProperties(string[] propertiesNames)
            {
                for (int i = 0; i < propertiesNames.Length; i++)
                {
                    if (this.RelatedObjectsMappings.ContainsKey(propertiesNames[i]))
                    {
                        string FieldName = this.RelatedObjectsMappings[propertiesNames[i]];
                        this.GetType().GetField(FieldName, BindingFlags.NonPublic).SetValue(this, null);
                    }
                }
            }

            private void containerObject_PropertyChanged(object sender, PropertyChangedEventArgs e)
            {
                this.ResetProperties(new string[] { e.PropertyName });
            }
            private void containerObject_AfterLoad(object sender, EventArgs e)
            {
                string[] propertiesNames = new string[this.RelatedObjectsMappings.Keys.Count];
                this.RelatedObjectsMappings.Keys.CopyTo(propertiesNames, 0);
                this.ResetProperties(propertiesNames);
            }

        }
        #endregion

    }
}
